import { Command, CommandCreate, CommandUpdate } from "../types/Command";
import axiosInstance from "./axios";

const API_URL = '/commands';

const CommandAPI = {
  // 查询所有命令
  getAll: (params?: Record<string, any>) => {
    return axiosInstance.get<Command[]>(`${API_URL}`, { params });
  },

  // 查询单条命令
  getById: (id: number) => {
    return axiosInstance.get<Command>(`${API_URL}/${id}`);
  },

  // 创建命令
  create: (data: CommandCreate) => {
    return axiosInstance.post<Command>(`${API_URL}`, data);
  },

  // 更新命令
  update: (id: number, data: CommandUpdate) => {
    return axiosInstance.put<Command>(`${API_URL}/${id}`, data);
  },

  // 删除命令
  delete: (id: number) => {
    return axiosInstance.delete<Command>(`${API_URL}/${id}`);
  },

  // 部署命令
  deploy: (id: number) => {
    return axiosInstance.post<{ message: string }>(`${API_URL}/deploy/${id}`);
  },

  // 下线命令
  offline: (id: number) => {
    return axiosInstance.post<{ message: string }>(`${API_URL}/offline/${id}`);
  }
};

export default CommandAPI;
